<!--  -->
<template>
  <a-form :model="form" layout="inline" size="mini">
    <a-form-item label="条形码">
      <a-input allow-clear class="bacClass" v-model="form.clothfiyCode" :style="{ width: '150px' }"
        @press-enter="huiche" />
    </a-form-item>
    <a-form-item label="织布单号">
      <a-input allow-clear class="bacClass" v-model="form.planOrderCode" :style="{ width: '150px' }"
        @press-enter="huiche" />
    </a-form-item>
    <a-form-item label="状态">
      <a-select popup-container="html" class="bacClass" :style="{ width: '150px' }" v-model="form.rowState" allow-clear
        allow-search @press-enter="huiche">
        <a-option :value="1">落布</a-option>
        <a-option :value="2">待处理</a-option>
        <a-option :value="3">已检验</a-option>
        <a-option :value="4">修补未处理</a-option>
        <a-option :value="5">修补中</a-option>
        <a-option :value="6">降等中</a-option>
        <a-option :value="7">待入次</a-option>
        <a-option :value="8">已入次</a-option>
        <a-option :value="9">已处理</a-option>
        <a-option :value="10">已入库</a-option>
        <a-option :value="11">已出库</a-option>
      </a-select>
    </a-form-item>
    <a-form-item label="日期">
      <a-range-picker popup-container="html" class="bacClass" :style="{ width: '250px' }" v-model="form.Dates"
        @select="onSelect" :disabledDate="disabledDate" @popupVisibleChange="onPopupVisibleChange"
        @change="DateChange" />
    </a-form-item>
    <a-form-item label="机台号">
      <a-input allow-clear class="bacClass" v-model="form.machineCode" :style="{ width: '150px' }"
        @press-enter="huiche" />
    </a-form-item>
  </a-form>
  <!-- '开需求单', -->
  <div class="cssToolbar">
    <Toolbar :items="[`查询`, '替换', '删除', '导出']" @select="cx" @tihuan="tihuans" @export="exports" @del="delSles">
    </Toolbar>
  </div>
  <div class="cssTable">
    <a-spin :loading="form.pageLoading" tip="加载中" dot style="height: 100%; width: 100%; z-index: 999">
      <AgGridVuesCopys :rowHeight="33" :headerHeight="33" :suppressCopyRowsToClipboard="true"
        :suppressDragLeaveHidesColumns="true" rowSelection="multiple" @grid-ready="gridReady"
        @columnResized="onColumnResized" @columnMoved="onColumnMoved" @columnVisible="onColumnVisible"
        @FilterChanged="FilterChangeds" :style="{ height: pageData.rHeight - 218 + 'px' }"
        :defaultColDef="defaultColDef" class="ag-theme-alpine" :rowData="dataList" :columnDefs="tc"
        :localeText="localeText1">
      </AgGridVuesCopys>
    </a-spin>
  </div>
  <div>
    <paginationCopys :page-size-options="pagingList1" :total="total" show-total show-jumper show-page-size
      @change="PageSize" @page-size-change="change1" style="justify-content: center" :page-size="size"
      :current="page" />
  </div>
  <el-dialog v-model="addWeightDialog2" :width="1200" title="修改" top="35vh">
    <el-table :data="tableData" border style="width: 100%">
      <el-table-column prop="recordType" label="类型" width="150">
        <template #default="scope">
          <div>{{
            scope.row.recordType == 0
              ? '初检'
              : scope.row.recordType == 1
                ? '抽检'
                : scope.row.recordType == 2
                  ? '复检'
                  : ''
          }}</div>
        </template>
      </el-table-column>
      <el-table-column prop="perchingGrade" label="等级" width="150" />
      <el-table-column prop="empName1" label="验布员1" width="150">
        <template #default="scope">
          <a-select popup-container="html" class="bacClass" :disabled="!scope.row.empName1" v-model="scope.row.empName1"
            allow-clear allow-search @click="empYuanGong" @change="empName1C($event, scope.row)">
            <a-option v-for="item in empList" :value="item['name']">{{ item['name'] }}</a-option>
          </a-select></template>
      </el-table-column>
      <el-table-column prop="empName2" label="验布员2" width="150">
        <template #default="scope">
          <a-select popup-container="html" class="bacClass" :disabled="!scope.row.empName2" v-model="scope.row.empName2"
            allow-clear allow-search @click="empYuanGong" @change="empName2C($event, scope.row)">
            <a-option v-for="item in empList" :value="item['name']">{{ item['name'] }}</a-option>
          </a-select></template>
      </el-table-column>
      <el-table-column prop="checkStaff1" label="值机员1" width="150">
        <template #default="scope">
          <a-select popup-container="html" class="bacClass" :disabled="!scope.row.checkStaff1"
            v-model="scope.row.checkStaff1" allow-clear allow-search @click="empYuanGong"
            @change="checkStaff1C($event, scope.row)">
            <a-option v-for="item in empList" :value="item['name']">{{ item['name'] }}</a-option>
          </a-select></template>
      </el-table-column>
      <el-table-column prop="checkStaff2" label="值机员2" width="150">
        <template #default="scope">
          <a-select popup-container="html" class="bacClass" :disabled="!scope.row.checkStaff2"
            v-model="scope.row.checkStaff2" allow-clear allow-search @click="empYuanGong"
            @change="checkStaff2C($event, scope.row)">
            <a-option v-for="item in empList" :value="item['name']">{{ item['name'] }}</a-option>
          </a-select></template>
      </el-table-column>
      <el-table-column prop="defectName" label="疵点" width="150" />
      <el-table-column prop="actualWeight" label="磅布重量" width="150">
        <!-- <template #default="scope">
                    <a-input-number v-model="scope.row.actualWeight" class="bacClass" :precision="4" />
                </template> -->
      </el-table-column>
      <el-table-column prop="posteriorWeight" label="验后重量" width="150">
        <!-- <template #default="scope">
                    <a-input-number v-model="scope.row.posteriorWeight" class="bacClass" :precision="4" />
                </template> -->
      </el-table-column>
      <el-table-column prop="timeClothShareWeight" label="次布重量" width="150">
        <!-- <template #default="scope">
                    <a-input-number v-model="scope.row.timeClothShareWeight" class="bacClass" :precision="4" />
                </template> -->
      </el-table-column>
      <el-table-column prop="checkWeight1" label="值机重量1" width="150">
        <!-- <template #default="scope">
                    <a-input-number v-model="scope.row.checkWeight1" class="bacClass" :precision="2" />
                </template> -->
      </el-table-column>
      <el-table-column prop="checkWeight2" label="值机重量2" width="150">
        <!-- <template #default="scope">
                    <a-input-number v-model="scope.row.checkWeight2" class="bacClass" :precision="2" />
                </template> -->
      </el-table-column>
      <el-table-column prop="checkRevolution1" label="值机转数1" width="150">
        <template #default="scope">
          <a-input-number v-model="scope.row.checkRevolution1" class="bacClass" :precision="2" />
        </template>
      </el-table-column>
      <el-table-column prop="checkRevolution2" label="值机转数2" width="150">
        <template #default="scope">
          <a-input-number v-model="scope.row.checkRevolution2" class="bacClass" :precision="2" />
        </template>
      </el-table-column>
      <el-table-column prop="fabricWeight1" label="次布重量1" width="150">
        <!-- <template #default="scope">
                    <a-input-number v-model="scope.row.fabricWeight1" class="bacClass" :precision="2" />
                </template> -->
      </el-table-column>
      <el-table-column prop="fabricWeight2" label="次布重量2" width="150">
        <!-- <template #default="scope">
                    <a-input-number v-model="scope.row.fabricWeight2" class="bacClass" :precision="2" />
                </template> -->
      </el-table-column>
    </el-table>
    <template #footer>
      <span class="dialog-footer">
        <el-button type="primary" @click="() => (addWeightDialog2 = false)">关闭</el-button>
        <el-button type="primary" @click="updatesSe">保存</el-button>
      </span>
    </template>
  </el-dialog>
  <!-- 落布修改 -->
  <el-dialog v-model="addWeightDialog4" :width="1080" :height="800" draggable>
    <template #title>
      <div>
        <center style="font-size: 20px"> 落布修改 </center>
      </div>
    </template>
    <AgGridVuesCopys :rowHeight="33" :headerHeight="33" :suppressCopyRowsToClipboard="true"
      :suppressDragLeaveHidesColumns="true" @grid-ready="gridReady4" style="height: 60vh; width: 100%"
      :defaultColDef="defaultColDef" class="ag-theme-alpine" :rowData="tableData4" :columnDefs="tc4"
      :localeText="localeText1"></AgGridVuesCopys>
    <template #footer>
      <span class="dialog-footer">
        <el-button type="primary" @click="() => (addWeightDialog4 = false)">关闭</el-button>
        <el-button type="primary" @click="save"> 确认 </el-button>
      </span>
    </template>
  </el-dialog>
  <el-dialog v-model="addWeightDialog3" :width="500" title="替换" top="35vh">
    <a-space>
      条形码:<a-input class="bacClass" v-model="tiaoxingma" :style="{ width: '300px' }" />
    </a-space>
    <template #footer>
      <span class="dialog-footer">
        <el-button type="primary" @click="() => (addWeightDialog3 = false)">关闭</el-button>
        <el-button type="primary" @click="tihuans2">替换</el-button>
      </span>
    </template>
  </el-dialog>
</template>

<script lang="ts" setup>
import { reactive, toRefs, ref, onMounted } from 'vue'
import Toolbar from '@/components/Toolbar.vue'
import { post, get } from '@/api/http'
import { Message, Modal } from '@arco-design/web-vue'

import { localeText } from '@/api/aggridZw'
import { pagingList } from '@/api/paging'
import { EXELTABLE } from '@/utils/exportEXCEL'
import dayjs from 'dayjs'
import { saveOrUpdateGridState as saveOrUpdateGridState01 } from '@/hooks/useGridState'
const pagingList1: any = ref(pagingList)
const localeText1: any = ref(localeText)

const defaultColDef: any = {
  sortable: true,
  resizable: true,
  filter: true,
}
const gridOption = ref()
const colState = ref()
const gridReady = (params: any) => {
  gridOption.value = params.api
  colState.value = params.columnApi
}

const gridOption4 = ref()
const colState4 = ref()
const gridReady4 = (params: any) => {
  gridOption4.value = params.api
  colState4.value = params.columnApi
}

const total = ref(0)
const page = ref(1)
const size = ref(10)
function PageSize(val: any) {
  page.value = val
  doRefresh()
}
function change1(val: any) {
  size.value = val
  doRefresh()
}

const dataList: any = ref([])
const countTotal = (arr: any, arrKey: string) => {
  return arr.reduce((s: any, v: any) => {
    if (v[arrKey] == null || v[arrKey] == '') {
      return (s += 0)
    }
    return (s += parseFloat(v[arrKey]))
  }, 0)
}
async function doRefresh() {
  form.pageLoading = true
  updateGridState01()
  try {
    const res = await post({
      url: 'qms/scannedGreyCloth/getClothfiyManage',
      data: {
        page: page.value,
        size: size.value,
        beginDate: !form.Dates[0] ? '' : form.Dates[0],
        endDate: !form.Dates[1] ? '' : form.Dates[1],
        clothfiyCode: form.clothfiyCode,
        planOrderCode: form.planOrderCode,
        rowState: form.rowState == '' ? 0 : form.rowState,
        machineCode: form.machineCode,
      },
    })
    if (res.code === 200) {
      dataList.value = res.data.list
      gridOption.value.setRowData(res.data.list)
      console.log(countTotal(res.data.list, 'checkWeight2'))
      gridOption.value.setFilterModel(null)
      gridOption.value.setPinnedBottomRowData([
        {
          ckbox: '总计',
          // machineGreyCode: res.data.list.length,
          // horseNo: res.data.list.length,
          checkWeight1: isNaN(countTotal(res.data.list, 'checkWeight1'))
            ? 0
            : countTotal(res.data.list, 'checkWeight1').toFixed(2),
          checkWeight2: isNaN(countTotal(res.data.list, 'checkWeight2'))
            ? 0
            : countTotal(res.data.list, 'checkWeight2').toFixed(2),
          checkRevolution1: isNaN(countTotal(res.data.list, 'checkRevolution1'))
            ? 0
            : countTotal(res.data.list, 'checkRevolution1'),
          checkRevolution2: isNaN(countTotal(res.data.list, 'checkRevolution2'))
            ? 0
            : countTotal(res.data.list, 'checkRevolution2'),
          theoryWeidht: isNaN(countTotal(res.data.list, 'theoryWeidht'))
            ? 0
            : countTotal(res.data.list, 'theoryWeidht').toFixed(2),
          actualWeight: isNaN(countTotal(res.data.list, 'actualWeight'))
            ? 0
            : countTotal(res.data.list, 'actualWeight').toFixed(2),
          posteriorWeight: isNaN(countTotal(res.data.list, 'posteriorWeight'))
            ? 0
            : countTotal(res.data.list, 'posteriorWeight').toFixed(2),
          timeClothShareWeight: isNaN(countTotal(res.data.list, 'timeClothShareWeight'))
            ? 0
            : countTotal(res.data.list, 'timeClothShareWeight').toFixed(2),
        },
      ])
      total.value = res.data.total
    } else {
      Message.error(res.message)
    }
  } catch (error) {
    console.log(error)
  } finally {
    form.pageLoading = false
  }
}

const cx = () => {
  page.value = 1
  doRefresh()
}

onMounted(() => {
  pageData.rHeight = document.getElementsByClassName('main-section')[0]?.clientHeight
  //弹出层的高
  if (pageData.rHeight !== undefined) {
    pageData.rHeight = pageData.rHeight
  }
  doRefresh()
})
const pageData = reactive({
  showAdd: false,
  rHeight: 0,
})

const tableColumns: any = [
  {
    title: '公司',
    key: 'compaynName',
    dataIndex: 'compaynName',
    width: 150,
  },
  {
    title: '条形码',
    key: 'clothfiyCode',
    dataIndex: 'clothfiyCode',
    width: 150,
  },
  {
    title: '一维码',
    key: 'barCode',
    dataIndex: 'barCode',
    width: 150,
  },
  {
    title: '织布单号',
    key: 'planOrderCode',
    dataIndex: 'planOrderCode',
    width: 150,
  },
  {
    title: '坯布编号',
    key: 'greyCode',
    dataIndex: 'greyCode',
    width: 150,
  },
  {
    title: '坯布名称',
    key: 'greyName',
    dataIndex: 'greyName',
    width: 200,
  },
  {
    title: '坯布批号',
    key: 'greyBatchNo',
    dataIndex: 'greyBatchNo',
    width: 200,
  },
  {
    title: '等级',
    key: 'grade',
    dataIndex: 'grade',
    width: 450,
  },
  {
    title: '机台号',
    key: 'machineCode',
    dataIndex: 'machineCode',
    width: 150,
  },
  {
    title: '机布号',
    key: 'machineGreyCode',
    dataIndex: 'machineGreyCode',
    width: 150,
  },
  {
    title: '匹号',
    key: 'horseNo',
    dataIndex: 'horseNo',
    width: 150,
    align: 'left',
  },
  {
    title: '验布员1',
    key: 'clothPerson1',
    dataIndex: 'clothPerson1',
    width: 150,
  },
  {
    title: '验布员2',
    key: 'clothPerson2',
    dataIndex: 'clothPerson2',
    width: 150,
  },
  {
    title: '值机员1',
    key: 'checkPerson1',
    dataIndex: 'checkPerson1',
    width: 150,
  },
  {
    title: '值机员2',
    key: 'checkPerson2',
    dataIndex: 'checkPerson2',
    slotName: 'checkPerson2',
    width: 150,
  },
  {
    title: '值机重量1',
    key: 'checkWeight1',
    dataIndex: 'checkWeight1',
    width: 150,
  },
  {
    title: '值机重量2',
    key: 'checkWeight2',
    dataIndex: 'checkWeight2',
    width: 150,
  },
  {
    title: '值机转数1',
    key: 'checkRevolution1',
    dataIndex: 'checkRevolution1',
    width: 150,
  },
  {
    title: '值机转数2',
    key: 'checkRevolution2',
    dataIndex: 'checkRevolution2',
    width: 150,
  },
  // {
  //     title: "次布重量1",
  //     key: "fabricWeight1",
  //     dataIndex: "fabricWeight1",
  //     width: 150,
  // },
  // {
  //     title: "次布重量2",
  //     key: "fabricWeight2",
  //     dataIndex: "fabricWeight2",
  //     width: 150,
  // },
  {
    title: '疵点问题',
    key: 'defectName',
    dataIndex: 'defectName',
    width: 150,
  },
  // {
  //     title: "落布重量",
  //     key: "pStartTime",//
  //     dataIndex: "pStartTime",//
  //     width: 150,
  // },
  {
    title: '落布重量',
    key: 'theoryWeidht',
    dataIndex: 'theoryWeidht',
    width: 150,
  },
  {
    title: '磅布重量',
    key: 'actualWeight',
    dataIndex: 'actualWeight',
    width: 150,
  },
  {
    title: '验后重量',
    key: 'posteriorWeight',
    dataIndex: 'posteriorWeight',
    width: 150,
  },
  {
    title: '次布重量',
    key: 'timeClothShareWeight',
    dataIndex: 'timeClothShareWeight',
    width: 150,
  },
  {
    title: '状态',
    key: 'rowState',
    dataIndex: 'rowState',
    width: 150,
    fixed: 'right',
  },
  {
    title: '时间',
    key: 'createTime',
    dataIndex: 'createTime',
    width: 150,
    fixed: 'right',
  },
  {
    title: '操作',
    key: 'alites',
    dataIndex: 'alites',
    slotName: 'alites',
    width: 80,
    fixed: 'right',
  },
]
let tc4: any[] = [
  {
    showRowGroup: 'hide_def',
    headerName: '',
    checkboxSelection: true,
    headerCheckboxSelection: true,
    pinned: 'left',
    width: 50,
    resizable: false,
    filter: false,
    sortable: false,
    minWidth: 50,
    maxWidth: 50,
    lockPosition: 'left',
  },
  {
    headerName: '织布单号',
    field: 'planOrderCode',
  },
  {
    headerName: '机台号',
    field: 'machineCode',
  },
  {
    headerName: '机布号',
    field: 'machineGreyCode',
  },
  {
    headerName: '匹号',
    field: 'horseNo',
  },
  {
    headerName: '条形码',
    field: 'clothfiyCode',
  },
  {
    headerName: '生产单号',
    field: 'weavingCode',
  },
  {
    headerName: '班次',
    field: 'shift',
    cellRenderer: {
      template: `
                    <el-tag v-if="b == 1" type="success">夜班</el-tag>
                    <el-tag v-if="b == 0" type="warning">白班</el-tag>
        `,
      setup(props: any) {
        return {
          b: props.params.data.shift,
        }
      },
    },
  },
  {
    headerName: '员工姓名',
    field: 'clothName',
    cellRenderer: {
      template: `<a-select popup-container="html"  class="bacClass" v-model="val.clothName" allow-clear
            allow-search @click="empY" @change="checkSt">
            <a-option v-for="item in empList" :value="item['name']">{{ item['name'] }}</a-option>
          </a-select>`,
      setup(props: any) {
        const val = ref(props.params.data)
        const empY = () => {
          post({
            url: '/org/hrEmployee/getEmpListByUser',
            data: {},
          }).then(({ data }) => {
            empList.value = data
          })
        }
        const checkSt = () => {
          empList.value.forEach((res: any) => {
            if (res.name == val.value.clothName) {
              val.value.staffCode = res.code
              val.value.clothUserId = res.id
            }
          })
        }
        return {
          val,
          empY,
          empList,
          checkSt
        }
      },
    },
  },
  {
    headerName: '总转数',
    field: 'convolution',
  },
  {
    headerName: '理论转数',
    field: 'theoryConvolution',
  },
  {
    headerName: '值机转数',
    field: 'joinConvolution',
    cellRenderer: {
      template: `<a-input-number class="bacClass" :min="0" :max="val.convolution" :precision="0"
                v-model="val.joinConvolution"></a-input-number>`,
      setup(props: any) {
        const val = ref(props.params.data)
        return {
          val,
        }
      },
    },
  },
]
let tc: any[] = tableColumns.map((o: any) => {
  let obj = {
    headerName: o.title,
    field: o.key,
    pinned: o['fixed'],
  }
  if (o.key === 'alites') {
    obj['resizable'] = false
    obj['filter'] = false
    obj['sortable'] = false
    obj['lockPosition'] = 'right'
    obj['width'] = 100
    obj['cellRenderer'] = {
      template: `
        <div v-if="data.ckbox=='总计'"></div>
        <el-button style="color:#165dff;" link @click="a2" v-else-if="a==1">落布修改</el-button>
        <el-button style="color:#165dff;" link @click="a1" v-else-if="a!=8&&a!=9&&a!=10&&a!=11">修改</el-button>
            <el-button style="color:#ccc;" link v-else>修改</el-button>`,
      setup(props: any) {
        const a2 = () => {
          post({
            url: '/planSingle/ClothScan/getList',
            data: {
              clothfiyCode: props.params.data.clothfiyCode,
            },
          }).then(({ code, data, message }) => {
            if (code == 200) {
              tableData4.value = data
              addWeightDialog4.value = true
            } else {
              Message.error(message)
            }
          })
        }
        const a1 = () => {
          post({
            url: 'qms/scannedGreyCloth/getScanGreyClothRecord',
            data: {
              clothfiyCode: props.params.data.clothfiyCode,
            },
          }).then(({ code, data, message }) => {
            if (code == 200) {
              tableData.value = data
              addWeightDialog2.value = true
            } else {
              Message.error(message)
            }
          })
        }
        return {
          a2,
          a1,
          a: props.params.data.rowState,
          data: props.params.data,
        }
      },
    }
  }
  if (o.key === 'rowState') {
    obj['resizable'] = false
    obj['filter'] = false
    obj['sortable'] = false
    obj['lockPosition'] = 'right'
    obj['width'] = 100
    obj['cellRenderer'] = {
      template: `
            <span v-if="a == 1">落布</span>
            <span v-if="a == 2">待处理</span>
            <span v-if="a == 3">已检验</span>
            <span v-if="a == 4">修补未处理</span>
            <span v-if="a == 5">修补中</span>
            <span v-if="a == 6">降等中</span>
            <span v-if="a == 7">待入次</span>
            <span v-if="a == 8">已入次</span>
            <span v-if="a == 9">已处理</span>
            <span v-if="a == 10">已入库</span>
            <span v-if="a == 11">已出库</span>
            `,
      setup(props: any) {
        return {
          a: props.params.data.rowState,
        }
      },
    }
  }
  return obj
})

let a = [
  {
    showRowGroup: 'hide_def',
    field: 'ckbox',
    headerName: '',
    checkboxSelection: true,
    headerCheckboxSelection: true,
    pinned: 'left',
    width: 100,
    resizable: false,
    filter: false,
    sortable: false,
    minWidth: 50,
    maxWidth: 150,
    lockPosition: 'left',
  },
]
tc = a.concat(tc)

const form: any = reactive({
  clothfiyCode: '',
  planOrderCode: '',
  rowState: '',
  machineCode: '',
  Dates: ['', ''],
})

const huiche = () => {
  doRefresh()
}

const addWeightDialog2 = ref(false)

const DateChange = (val: any) => {
  if (!val) {
    form.Dates = ['', '']
  }
}

const dates: any = ref([])

const onSelect = (valueString: any, value: any) => {
  dates.value = value
}

const disabledDate = (current: any) => {
  const dates1 = dates.value
  if (dates1 && dates1.length) {
    const tooLate =
      dates1[0] && Math.abs((new Date(current) - dates1[0]) / (24 * 60 * 60 * 1000)) > 6
    const tooEarly =
      dates1[1] && Math.abs((new Date(current) - dates1[1]) / (24 * 60 * 60 * 1000)) > 6
    return tooEarly || tooLate
  }
  return false
}

const onPopupVisibleChange = (visible: any) => {
  if (!visible) {
    dates.value = []
  }
}

const tableData: any = ref([])
const tableData4: any = ref([])
const addWeightDialog3 = ref(false)
const addWeightDialog4 = ref(false)

const tiaoxingma: any = ref('')

const tihuans = () => {
  if (gridOption.value.getSelectedRows().length == 0) {
    Message.error('请勾选数据')
    return
  }
  if (gridOption.value.getSelectedRows().length > 1) {
    Message.error('单条替换')
    return
  }
  if (
    gridOption.value.getSelectedRows()[0].rowState == 8 ||
    gridOption.value.getSelectedRows()[0].rowState == 9 ||
    gridOption.value.getSelectedRows()[0].rowState == 10 ||
    gridOption.value.getSelectedRows()[0].rowState == 11
  ) {
    Message.error('该状态不可替换')
    return
  }
  tiaoxingma.value = gridOption.value.getSelectedRows()[0].clothfiyCode
  addWeightDialog3.value = true
}

const exports = () => {
  // if (gridOption.value.getSelectedRows().length == 0) {
  //     Message.error('请勾选数据')
  //     return
  // }
  // EXELTABLE(tc, gridOption.value.getSelectedRows().map((res: any) => {
  //     return {
  //         ...res,
  //         rowState: res.rowState == 1 ? '落布' : res.rowState == 2 ? '待处理' : res.rowState == 3 ? '已检验' : res.rowState == 4 ? '修补未处理' : res.rowState == 5 ? '修补中' : res.rowState == 6 ? '降等中' : res.rowState == 7 ? '待入次' : res.rowState == 8 ? '已入次' : res.rowState == 9 ? '已处理' : res.rowState == 10 ? '已入库' : res.rowState == 11 ? '已出库' : ''
  //     }
  // }), '坯布生产过程表')
  post({
    url: '/qms/scannedGreyCloth/getClothfiyManageExport',
    data: {
      beginDate: !form.Dates[0] ? '' : form.Dates[0],
      endDate: !form.Dates[1] ? '' : form.Dates[1],
      clothfiyCode: form.clothfiyCode,
      planOrderCode: form.planOrderCode,
      rowState: form.rowState == '' ? 0 : form.rowState,
    },
  }).then(({ data, code }: any) => {
    if (code === 200) {
      EXELTABLE(tc, data, '坯布生产过程表')
    }
  })
}

const delSles = () => {
  if (gridOption.value.getSelectedRows().length == 0) {
    Message.error('请勾选数据')
    return false
  }
  if (gridOption.value.getSelectedRows().length > 1) {
    Message.error('单条删除')
    return false
  }
  if (
    gridOption.value.getSelectedRows()[0].rowState == 8 ||
    gridOption.value.getSelectedRows()[0].rowState == 9 ||
    gridOption.value.getSelectedRows()[0].rowState == 10 ||
    gridOption.value.getSelectedRows()[0].rowState == 11
  ) {
    Message.error('该状态不可删除')
    return
  }
  Modal.confirm({
    title: '系统提示',
    content: '确认删除选中的数据?',
    onOk: () => {
      post({
        url: 'qms/scannedGreyCloth/deleteClothfiyManage',
        data: {
          clothfiyCode: gridOption.value.getSelectedRows()[0].clothfiyCode,
        },
      }).then((res: any) => {
        if (res.code == 200) {
          Message.success('成功')
          doRefresh()
        } else Message.error(res.message)
      })
    },
  })
}

const tihuans2 = () => {
  post({
    url: 'qms/scannedGreyCloth/replaceScanGreyCloth',
    data: {
      oldClothfiyCode: gridOption.value.getSelectedRows()[0].clothfiyCode,
      newClothfiyCode: tiaoxingma.value,
    },
  }).then(({ code, message, data }) => {
    if (code == 200) {
      Message.success(message)
      addWeightDialog3.value = false
      doRefresh()
    } else {
      Message.error(data)
    }
  })
}

const empList = ref([])

const empYuanGong = () => {
  post({
    url: '/org/hrEmployee/getEmpListByUser',
    data: {},
  }).then(({ data }) => {
    empList.value = data
  })
}

const empName1C = (val: any, Obj: any) => {
  empList.value.forEach((res: any) => {
    if (res.name == val) {
      Obj.empCode1 = res.code
      Obj.empId1 = res.id
    }
  })
}

const empName2C = (val: any, Obj: any) => {
  empList.value.forEach((res: any) => {
    if (res.name == val) {
      Obj.empCode2 = res.code
      Obj.empId2 = res.id
    }
  })
}

const checkStaff1C = (val: any, Obj: any) => {
  empList.value.forEach((res: any) => {
    if (res.name == val) {
      Obj.checkStaffCode1 = res.code
      Obj.checkEmpId1 = res.id
    }
  })
}

const checkStaff2C = (val: any, Obj: any) => {
  empList.value.forEach((res: any) => {
    if (res.name == val) {
      Obj.checkStaffCode2 = res.code
      Obj.checkEmpId2 = res.id
    }
  })
}

const updatesSe = () => {
  post({
    url: 'qms/scannedGreyCloth/updateScanGreyCloth',
    data: tableData.value,
  }).then(({ code, message }) => {
    if (code == 200) {
      addWeightDialog2.value = false
      doRefresh()
      Message.success(message)
    } else {
      Message.error(message)
    }
  })
}
const save = () => {
  post({
    url: '/planSingle/ClothScan/update',
    data: tableData4.value,
  }).then(({ code, message }) => {
    if (code == 200) {
      addWeightDialog4.value = false
      doRefresh()
      Message.success(message)
    } else {
      Message.error(message)
    }
  })
}

const { saveGridState: saveGridState01, updateGridState: updateGridState01 } =
  saveOrUpdateGridState01('shengChanGuoChengs-1', gridOption, colState, tc)

const onColumnMoved = () => {
  saveGridState01()
}

const onColumnResized = () => {
  saveGridState01()
}

const onColumnVisible = () => {
  saveGridState01()
}

const FilterChangeds = (params: any) => {
  let dataList: any = []
  params.api.forEachNodeAfterFilter((row: any) => {
    dataList.push(row.data)
  })
  gridOption.value.setPinnedBottomRowData([
    {
      ckbox: '总计',
      machineGreyCode: dataList.length,
      horseNo: dataList.length,
      checkWeight1: isNaN(countTotal(dataList, 'checkWeight1'))
        ? 0
        : countTotal(dataList, 'checkWeight1').toFixed(2),
      checkWeight2: isNaN(countTotal(dataList, 'checkWeight2'))
        ? 0
        : countTotal(dataList, 'checkWeight2').toFixed(2),
      checkRevolution1: isNaN(countTotal(dataList, 'checkRevolution1'))
        ? 0
        : countTotal(dataList, 'checkRevolution1'),
      checkRevolution2: isNaN(countTotal(dataList, 'checkRevolution2'))
        ? 0
        : countTotal(dataList, 'checkRevolution2'),
      theoryWeidht: isNaN(countTotal(dataList, 'theoryWeidht'))
        ? 0
        : countTotal(dataList, 'theoryWeidht').toFixed(2),
      actualWeight: isNaN(countTotal(dataList, 'actualWeight'))
        ? 0
        : countTotal(dataList, 'actualWeight').toFixed(2),
      posteriorWeight: isNaN(countTotal(dataList, 'posteriorWeight'))
        ? 0
        : countTotal(dataList, 'posteriorWeight').toFixed(2),
      timeClothShareWeight: isNaN(countTotal(dataList, 'timeClothShareWeight'))
        ? 0
        : countTotal(dataList, 'timeClothShareWeight').toFixed(2),
    },
  ])
}

</script>
<style lang="less" scoped>
.cssToolbar {
  text-align: right;
  margin-bottom: 2px;
}

.footer {
  width: 100%;
  margin: 0 auto;
  margin-top: 20px;
  text-align: left;

  .footer2 {
    width: 100%;
    text-align: right;
    font-size: 20px;
    font-weight: 600;
  }
}

.tbody {
  white-space: nowrap;
  justify-content: center;

  .td {
    text-align: center;
    box-sizing: border-box;
    display: inline-block;
  }

  text-align: left;
}

.trTds {
  font-size: 16px;
  font-weight: 600;
}

:deep(.ag-cell) {
  border-right: 1px solid #dde2eb;
}

:deep(.ag-header-cell) {
  border-right: 1px solid #dde2eb;
}

:deep(.ag-cell-value) {
  user-select: initial;
  -moz-user-select: text;
  -ms-user-select: text;
  -webkit-user-select: text;
}

:deep(.arco-table-td-content) {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
</style>
